/**
 * $Id: IrcUser.cs 77 2004-09-19 13:31:53Z meebey $
 * $URL: svn://svn.qnetp.net/smartirc/IrcClient/tags/0.2.0/src/IrcUser.cs $
 * $Rev: 77 $
 * $Author: meebey $
 * $Date: 2004-09-19 15:31:53 +0200 (Sun, 19 Sep 2004) $
 *
 * Copyright (c) 2003 Mirco 'meebey' Bauer <mail@meebey.net> <http://www.meebey.net>
 * 
 * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using System.Collections.Specialized;

namespace UrDnd.IrcClient
{
	/// <summary>
	///
	/// </summary>
	public class IrcUser
	{
		private readonly IrcClient _ircClient;

		public IrcUser(string nickname, IrcClient ircClient)
		{
		    HopCount = -1;
		    _ircClient = ircClient;
			Nick = nickname;
		}

		public IrcUser(IrcUser other)
		{
			Nick = other.Nick;
			_ircClient = other._ircClient;
			Ident = other.Ident;
			Host = other.Host;
			Realname = other.Realname;
			IsIrcOp = other.IsIrcOp;
			IsAway = other.IsAway;
			Server = other.Server;
			HopCount = other.HopCount;
		}

		public string Nick { get; set; }

		public string Ident { get; set; }

	    public string Host { get; set; }

	    public string Realname { get; set; }

	    public bool IsIrcOp { get; set; }

	    public bool IsAway { get; set; }

	    public string Server { get; set; }

	    public int HopCount { get; set; }

	    public string[] JoinedChannels
		{
			get
			{
			    var channels = _ircClient.GetChannels();
				var joinedchannels = new StringCollection();

				foreach (var channelname in channels)
				{
				    var channel = _ircClient.GetChannel(channelname);
				    if (channel.UnsafeUsers.Contains(Nick.ToLower()))
						joinedchannels.Add(channelname);
				}

			    var result = new string[joinedchannels.Count];
				joinedchannels.CopyTo(result, 0);
				return result;
			}
		}
	}
}